package com.wayin.lift.controller.check;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.wayin.lift.entityVO.ClockInVO;
import com.wayin.lift.entityVO.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wayin.lift.entity.ClockInEntity;
import com.wayin.lift.service.ClockInService;
import com.wayin.common.utils.*;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;

/**
 * 考勤表
 *
 * @author HYXK
 * @email null@qq.com
 * @date 2020-05-26 09:56:38
 */
@Api(tags = "考勤表接口")
@RestController
@RequestMapping("/clockIn")
public class ClockInController {

    @Autowired
    private ClockInService clockInService;

    /**
     * 列表
     */
    @ApiOperation("查找所有考勤表信息")
    @RequestMapping(value = "/list", method = GET)
    public R list(Long pId){
        List<ClockInVO> page = clockInService.findAllVO(pId);

        return R.ok().put("page", page);
    }

    /**
     * 根据月份查找考勤情况
     */
    @ApiOperation("根据月份查找考勤情况")
    @RequestMapping(value = "/situation", method = GET)
    public R situation(String cDate){
        Map<String, List<ResultVO>> map = clockInService.findSituation(cDate);

        return R.ok().put("situation", map);
    }


    /**
     * 信息
     */
    @ApiOperation("根据{cId}查找考勤表信息")
    @RequestMapping(value = "/info/{cId}", method = GET)
    public R info(@PathVariable("cId") Long cId){
		ClockInEntity clockIn = clockInService.getById(cId);

        return R.ok().put("clockIn", clockIn);
    }

    /**
     * 保存
     */
    @ApiOperation("添加考勤表信息")
    @RequestMapping(value = "/save", method = POST)
    public R save(@RequestBody ClockInEntity clockIn){

        return clockInService.save(clockIn) ? R.ok() : R.error();
    }

    /**
     * 修改
     */
    @ApiOperation("修改考勤表信息")
    @RequestMapping(value = "/update", method = POST)
    public R update(@RequestBody ClockInEntity clockIn){

        return clockInService.updateById(clockIn) ? R.ok() : R.error();
    }

    /**
     * 删除
     */
    @ApiOperation("删除考勤表信息")
    @RequestMapping(value = "/delete", method = PUT)
    public R delete(@RequestParam Long[] cIds){

        return clockInService.removeByIds(Arrays.asList(cIds)) ? R.ok() : R.error();
    }

}
